using UnityEngine;
using System.Collections;

public class Control : MonoBehaviour {

	static bool open = false;//remark if the fan has opened.
	int    selection = 0;//remark which selection has been selected.
	static bool rotateFan = false; //if has pressed key.
	static bool canExecute = false;//if can execute ,in case of execute many times when press keyboard one times.

//	string[] selectionName = new string[12];//
//	string[0] = "sdf";
//	string[12] = {"3right", "2right", "1right", "1left", "2left", "3left", "4left", "5left", "6left", "6right", "5right", "4right"};
	// Use this for initialization
	void Start () {
	}
	

	
	// Update is called once per frame
	void Update () 
	{		
		if (open == false && Input.GetKeyDown(KeyCode.B))
		{
			print("open");
			animation.Play("open");
//			yield StartCoroutine("Do");
//			animation.Play("5right");
			open = true;
		}
		else 
		{
			if (Input.GetKeyDown(KeyCode.LeftArrow))
			{
				canExecute = true;
				if (rotateFan == true)
				{
					--selection;
					if (selection < 1)
						selection = 1;
					else if (selection > 12)
						selection =12;
					print(selection);
				}
				else 
				{
					rotateFan = true;
					selection = 6;
					print("6");
				}
			}
			
			if (Input.GetKeyDown(KeyCode.RightArrow))
			{
				canExecute = true;
				if (rotateFan == true)
				{
					++selection;
					if (selection < 1)
						selection = 1;
					else if (selection > 12)
						selection =12;
					print(selection);
				}
				else 
				{
					rotateFan = true;
					selection = 7;
					print("7");
				}
			}
			
			if (canExecute == true)
			{
				switch(selection)
				{
//				RunFrontBehaviour();//run the animation before the selection.
				case 1: animation.CrossFade("1left");
					break;
				case 2:animation.CrossFade("1right");
					break;
				case 3:animation.CrossFade("2left");
					break;
				case 4:animation.CrossFade("2right");
					break;
				case 5:animation.CrossFade("3left");
					break;
				case 6:animation.CrossFade("3right");
					break;
				case 7:animation.CrossFade("4left");
					break;
				case 8:animation.Play("4right");
					break;
				case 9:animation.CrossFade("5left");
					break;
				case 10:animation.CrossFade("5right");
					break;
				case 11:animation.CrossFade("6left");
					break;
				case 12:animation.CrossFade("6right");
					break;
				}
				canExecute = false;
			}
		}

/*	IEnumerator  Do()
	{
	yield WaitForSeconds(2);
	}
*/
	}
}